package com.shuzijun.leetcode.editor.cn;
public class MoveZeroes{
    public static void main(String[] args) {
         Solution solution = new MoveZeroes().new Solution();
         solution.moveZeroes(new int[]{0,1,0,3,12});
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public void moveZeroes(int[] nums) {
        int p = -1;
        int q = 0;
        while (q < nums.length){
            if (nums[q] == 0){
                q++;
                continue;
            }
            if (nums[q] !=0){
                swap(nums,p+1,q);
                p++;
                q++;
            }
        }
    }

        private void swap(int[] nums, int i, int j) {
            int tmp = nums[i];
            nums[i] = nums[j];
            nums[j] = tmp;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}